import axios from 'axios'
import Cookies from 'js-cookie'

export const request = axios.create({
  baseURL: 'http://localhost:8000',
  timeout: 15000,
})

request.interceptors.request.use(
  (config) => {
    const token = Cookies.get('Authorization')

    token && (config.headers.Authorization = token)

    return config
  },
  (err) => {
    return Promise.reject(err)
  }
)

request.interceptors.response.use(
  (result) => {
    return result.data
  },
  (err) => {
    return Promise.reject(err)
  }
)
